package cn.glenn._01mvcboot01.controller;

import cn.glenn._01mvcboot01.pojo.dto.BmiDTO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class BMIController {
/*    @GetMapping("/bmi")
    @ResponseBody
    public String bmi(BmiDTO bc) {
        double weight = bc.getWeight();
        double height = bc.getHeight();
        double bmi = weight / (height * height);
        if (bmi < 18.5) {
            return bmi + "体重偏瘦";
        }
        if (bmi < 24) {
            return bmi + "体重正常";
        }
        if (bmi < 27) {
            return bmi + "微胖";
        }
        return bmi + "该减肥了";
    }*/
    @GetMapping("/bmi/{height}/{weight}")
    @ResponseBody
    public String bmi(@PathVariable double height,
                      @PathVariable double weight) {
//        double weight = bc.getWeight();
//        double height = bc.getHeight();
        double bmi = weight / (height * height);
        if (bmi < 18.5) {
            return bmi + "体重偏瘦";
        }
        if (bmi < 24) {
            return bmi + "体重正常";
        }
        if (bmi < 27) {
            return bmi + "微胖";
        }
        return bmi + "该减肥了";
    }

}
